﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cosmetic.Logic;

namespace WebApp
{
    public partial class Login : System.Web.UI.Page
    {
        private UserManager m_UserManager = new UserManager();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (this.TextBox1.Text == "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('请填写的您用户名!');", true);
                return;
            }
            Cosmetic.DataEntity.User theUser = m_UserManager.LoginValidate(this.TextBox1.Text.Trim(), this.TextBox2.Text.Trim());

            if (theUser == null)
            {
                theUser = m_UserManager.loginValidate1(this.TextBox1.Text.Trim(), this.TextBox2.Text.Trim());
            }
            if (theUser == null)
            {
                Session.Remove("SignInUser");
                Cosmetic.WebGeneric.WebMessageBox("用户名或密码错误!", this.Page);
            }
            else
            {
                Session["SignInUser"] = theUser;
                Session["userid"] = theUser.UserId;
                Session["tel"] = theUser.tel;
                Session["UserName"] = theUser.UserName;
                Session["password"] = theUser.Password;
                Cosmetic.WebGeneric.WebMessageBox("登录成功!", this.Page);
                if (!String.IsNullOrEmpty(this.Request.QueryString["R"]))
                {
                    this.Response.Redirect(this.Request.QueryString["R"]);
                }
                else
                {
                    this.Response.Redirect("~/Space/BasicInfo.aspx");
                }
            }
        }
    }
}